/**
 * Created by Chen on 2016/3/6.
 */

define(function(require, exports, module){

    var $ = require('jquery');
    var List = require('../../util/list.js');
    require('jquery.validate');
    require('jquery.icheck');
    require('bootstrap');
    require('bootstrap.select');
    require('jquery.layer');

    // 初始化
    $('input').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
    });



    $("#topic-submit").on("click",function() {
        var topic_id = $("#id").val();
        var data = {"id": topic_id};
        var curNum = $("#studentNumber").val();
        var total = $("#restriction").val();
        var pass = $("#pass").val();

        layer.confirm('是否选择该题目？', {
            btn: ['确定', '取消'], //按钮
            shade: false //不显示遮罩
        }, function () {
            if (pass != 3) {
                layer.msg('不能选择该题目', {
                    icon: 9,
                    time: 2000
                });
            }else if (curNum == total) {
                layer.msg('人数已满', {
                    icon: 9,
                    time: 2000
                });
            }
            else {
                var posting = $.post($CONFIG.base_url + "/api/topic/student/ask_for", data);
                posting.done(function (data) {
                    if (data == true) {
                        layer.msg('选择成功', {
                            icon: 9,
                            time: 1000
                        }, function () {
                            window.location.href = $CONFIG.base_url + "/student/choice/manage";
                        });
                    }
                    if (data == false) {
                        layer.msg('您已选过题目了', {icon: 9});
                    }
                });
            }
        }, function () {
        });
    });


});
